#include<iostream>
#include<algorithm>
using namespace std;
const int N = 110;
int n, m;
int arr[N][N];
int dp[N][N];
int main()
{
	int t = 0;
	cin >> t;
	while (t--) {
		cin >> n >> m;
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= m; j++) {
				cin >> arr[i][j];
			}
		}
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= m; j++) {
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + arr[i][j];
			}
		}
		cout << dp[n][m] << endl;
	}
	return 0;
}